from Linac import *
from globals import loadLinacInfo
import time as t

#####Build linac from data#####
#Drifts = loadLinacInfo('HS_2011_11_23_Plasma-Surface_To_Target.txt','DR_13','DR_493')
Drifts = loadLinacInfo('HS_2011_11_23_Plasma-Surface_To_Target.txt','DR_124','DR_493')

Cavities = CavitySection(file='EllipticalSection.csv',E_final=2512e6)
#Cavities.AddRFError(0.005,0.0014,distr='Uniform')


#####Create Pulse#####
numBunches = 1e4
tb = 1/352e6
Ib = 50e-3
P1 = Pulse(numBunches,Cavities.cavNum, tb, Ib)

Esig = 0.078e6
tsig = 0.4*np.pi/180/360/704.4e6
Ibsig = 40e-3

P1.AddEnergyError(Esig)
P1.AddTimeError(tsig)
P1.AddCurrentError(Ibsig)

#####Create HOMs#####
homfreq = 1e9
homQex = 1e7
homRoverQ = 1

H1 = HOM(Cavities.cavNum,homfreq,homQex,homRoverQ)

fsig = 0.1e6
H1.AddFrequencyError(fsig)

#####Create Linac ready to track#####
Lin = Linac(Cavities,Drifts,P1)

t0 = t.time()
Lin.Track()
print 'Tracked', int(P1.numBunches), 'bunches in', t.time() - t0, 'secs'
